function UserInfo(id, userName, profilePicture) {
    this.id = id;
    this.username = userName;
    this.profilePicture = profilePicture; 
    this.setLocation = function(lat, lng, height){
        this.lat = lat;
        this.lng = lng;
        this.height = height;
    };
    this.getLocation = function() {
        return new google.maps.LatLng(this.lat, this.lng);
    };
    this.setMarker = function(marker){
        this.marker = marker;
    };
}

function addMarker(location,map) {
    var marker = new google.maps.Marker({
        position: location,
        map: map
    });
    return marker;
}

function addMarker(location,map,image) {
    var marker = new google.maps.Marker({
        position: location,
        map: map,
        icon:image
    });
    return marker;
}

function initializeMap(user, map, image, coordinates){
    var location =user.getLocation();
    var marker = addMarker(location, map, image);
    user.setMarker(marker);
    drawRoute(coordinates, map);
}

function drawRoute(coordinates, map){
    var route = new google.maps.Polyline({
        path: coordinates,
        strokeColor: "#FF0000",
        strokeOpacity: 1.0,
        strokeWeight: 2
    });

    route.setMap(map);
}

//liveLocationFeedCommingEvent handler
function updateUserPosition(jsonObject){
    if(jsonObject.username == user.username){
        drawLine(new google.maps.LatLng(user.lat, user.lng),
            new google.maps.LatLng(jsonObject.lat, jsonObject.lng), map);
            
        user.lat = jsonObject.lat;
        user.lng = jsonObject.lng;
        user.height = jsonObject.height;
        user.speed = jsonObject.speed;
        
        if(user.marker != null)
            user.marker.setPosition(new google.maps.LatLng(athlete.lat, athlete.lng));
    }
}

function drawLine(oldLocation, newLocation, map){
    var coordinates = [oldLocation, newLocation];
    var line = new google.maps.Polyline({
        path: coordinates,
        strokeColor: "#FF0000",
        strokeOpacity: 1.0,
        strokeWeight: 2
    });

    line.setMap(map);
}